<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cesium-3dTiles-4490</title>
    <link rel="stylesheet" href="http://192.168.1.90:8088/lib/cesium-1.90-4490/Cesium/Widgets/widgets.css" type="text/css">
    <script src="http://192.168.1.90:8088/lib/cesium-1.90-4490/Cesium/Cesium.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #cesiumContainer {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>

<body>
<div id="cesiumContainer"></div>
<script>

    //Cesium token
    let cesium_tk = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWRlMmQ1Ni1iNGMxLTRhY2YtYmExYi1jNjYyNTUxNDhjYzgiLCJpZCI6MjMwODAsInNjb3BlcyI6WyJhc2wiLCJhc3IiLCJhc3ciLCJnYyIsInByIl0sImlhdCI6MTU4OTE4NzE1NH0.QrUVmI13wKIqFwmnsGSR6aMr8FEtbO7jsTA0mqnvbdM";

    let type = 'img'
    Cesium.Ion.defaultAccessToken = cesium_tk;
    window.viewer = new Cesium.Viewer('cesiumContainer', {
        // imageryProvider: layer,
        geocoder: false,
        homeButton: false,
        sceneModePicker: false,
        baseLayerPicker: false,
        navigationHelpButton: false,
        animation: false,
        timeline: false,
        fullscreenButton: false,
        vrButton: false,
        infoBox: false,
        selectionIndicator: false
        // shouldAnimate: true
    });
    // Globe 对象
    let globe = window.viewer.scene.globe;
    // 一定要为 true，否则 undergroundColor 设置无效
    globe.translucency.enabled = true;
    // 基础色透明，默认是蓝色 Cesium.Color.BLUE
    globe.baseColor = Cesium.Color.TRANSPARENT;
    // 地下色透明，默认是黑色 Cesium.Color.BLACK
    globe.undergroundColor = Cesium.Color.TRANSPARENT;
    // 隐藏天空大气层，否则最外围有一圈
    window.viewer.scene.skyAtmosphere.show = false;
    // 不显示底图
    window.viewer.imageryLayers.get(0).show = false;
    // 隐藏地球实体
    // window.viewer.scene.globe.show = false;
    window.viewer.scene.screenSpaceCameraController.enableCollisionDetection = false;
    window.viewer._cesiumWidget._creditContainer.style.display = "none";// 隐藏 LOGO 版权

    let imageryLayers = window.viewer.imageryLayers;
    let imageryProvider = new Cesium.ArcGisMapServerImageryProvider({
        url : "https://jiangsu.tianditu.gov.cn/mapjs2/rest/services/MapJS/js_yxdt_latest/MapServer",
    })
    let testLayer = imageryLayers.addImageryProvider(imageryProvider);
    testLayer.show = true


    function  flyToMapByExtent() {
        window.viewer.camera.setView({
            destination : Cesium.Cartesian3.fromDegrees(120.46292388403401, 32.53487644346701, 130000.0),//摄像机在 WGS84（世界）坐标中的最终位置，或从自上而下视图可见的矩形
            orientation : {//包含方向和向上属性或航向、俯仰和滚动属性的对象
                heading : Cesium.Math.toRadians(0), // （方向）east, default value is 0.0 (north)此处可根据个人需求实际取值
                pitch : Cesium.Math.toRadians(-90),    // （视角）default value (looking down)此处可根据个人需求实际取值
                roll : 0.0                             //（倾斜角度） default value此处可根据个人需求实际取值
            }
        });
    }

    flyToMapByExtent()

    // 定义最小高度，对应于2D地图的zoom level 19。
    // 注意：这个值不是精确对应，需要根据实际需求调整。
    var minCameraHeight = 100; // 以米为单位



    window.viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
        url: 'http://192.168.1.90:8088/3dtiles/jssdem'
    });
    window.viewer.scene.globe.terrainExaggeration = 1;

    var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
        url: 'http://192.168.1.90:8088/jinhu/merge/tileset.json',
        modelMatrix: Cesium.Matrix4.fromArray([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),
        kipLevelOfDetail: true,
        baseScreenSpaceError: 1024,
        maximumScreenSpaceError: 64, // 数值加大，能让最终成像变模糊
        skipScreenSpaceErrorFactor: 16,
        skipLevels: 1,
        immediatelyLoadDesiredLevelOfDetail: false,
        loadSiblings: true, // 如果为true则不会在已加载完概况房屋后，自动从中心开始超清化房屋
        cullWithChildrenBounds: true,
        cullRequestsWhileMoving: true,
        cullRequestsWhileMovingMultiplier: 10, // 值越小能够更快的剔除
        preloadWhenHidden: true,
        preferLeaves: true,
        maximumMemoryUsage: 512, // 内存分配变小有利于倾斜摄影数据回收，提升性能体验
        progressiveResolutionHeightFraction: 0.5, // 数值偏于0能够让初始加载变得模糊
        // dynamicScreenSpaceErrorDensity: 0.1, // 数值加大，能让周边加载变快
        dynamicScreenSpaceErrorDensity: 1, // 数值加大，能让周边加载变快
        dynamicScreenSpaceErrorFactor: 1, // 不知道起了什么作用没，反正放着吧先
        dynamicScreenSpaceError: true // 根据测试，有了这个后，会在真正的全屏加载完之后才清晰化房屋
    }));
    window.viewer.flyTo(tileset);



</script>


</body>
</html>